/**
 * 
 */
package wpmp.portal.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import wpmp.security.client.internal.SecurityUtils;
import wpmp.utils.quickbean.UserView;

/**
 * @author Wayne.Wang<5waynewang@gmail.com>
 * @since 11:49:07 AM Dec 5, 2013
 */
public abstract class BaseController {

	protected final Logger log = LoggerFactory.getLogger(getClass());

	protected UserView getUserView(HttpServletRequest req) {
		final String securityId = SecurityUtils.getSecurityId(req);
		return getUserView(req, securityId);
	}

	protected UserView getUserView(HttpServletRequest req, String securityId) {
		final String key = "UserView_" + securityId;
		return (UserView) req.getSession().getAttribute(key);
	}

	protected void setUserView(HttpServletRequest req, UserView userView) {
		final String key = "UserView_" + userView.getSecurityId();
		req.getSession().setAttribute(key, userView);
	}

	protected void removeUserView(HttpServletRequest req) {
		final String securityId = SecurityUtils.getSecurityId(req);
		final String key = "UserView_" + securityId;
		req.getSession().removeAttribute(key);
	}
}
